(function($) {
	
	$.fn.isCourseDisplay = function(){
		
		//getServerTime
		function getServerTime() {
			var now = null,
			url = [$.global.getContextPath(), '/syncTime'].join('');
		
			$.ajax({
			    url: url, 
		        async: false, 
		        dataType: 'text',
		        beforeSend: function (xhr) {
					 xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
				},
		        success: function(ms) {
					now = new Date(+ms);
		        }, 
		        error: function(http, message, exc) {
		        	now = null; 
		    	}
			});
			
			return now;
		}
		
		return $(this).each(function(){
			
			//简介中的空行
			$('.course_detail p').each(function() {
				if($(this).height() < 21) {
					$(this).height(21);
				}
			});

			//startTime count down
			$('.time_show').each(function(){
				var enterTime = parseInt($('#sms_reminder').find('.start_time').val())
				  , suplusDays = parseInt($('#sms_reminder').find('.suplus_days').val())
				  , suplusHours = parseInt($('#sms_reminder').find('.suplus_hours').val())
				  , timeUp = function(){
						$('.add_course_schedule').hide();
						$('.before_start').hide();
						$('.count_down_over').show();
					}
				  , layout;
				
				if(suplusDays > 0) {
					layout='<span>{dn}{dl}{hn}{hl}{mn}{ml}{sn}{sl}</span>';
				} else if(suplusHours > 0){
					layout='<span>{hn}{hl}{mn}{ml}{sn}{sl}</span>';
				} else {
					layout='<span>{mn}{ml}{sn}{sl}</span>';
				}
				
				$(this).countdown({
					until: new Date(enterTime),
					layout: layout,
					onExpiry: function(){
						timeUp();
					},
					serverSync: getServerTime
				});
			});
			
			//bounce attend bar from bottom
			$.extend($.easing, {
				easeOutBounce: function (x, t, b, c, d) {
					if ((t /= d) < (1 / 2.75)) {
						return c * (7.5625 * t * t) + b;
					} else if (t < (2 / 2.75)) {
						return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
					} else if (t < (2.5 / 2.75)) {
						return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b;
					} else {
						return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
					}
				}
			});
		
			setTimeout(function(){
				$('#add_schedule').slideDown({
					duration: 1618,
					easing: 'easeOutBounce'
				});
			}, 500);
			
			$('#cancel_schedule').click(function(){
				$('#add_schedule').slideUp();
			});
			
			//attend list page turn
			$('a', $('#page_scroll')).live('click', function(){
				
				if($(this).hasClass('disabled')) {
					return false;
				} else{
					$.ajax({
						async:false,
						url:$(this).attr('href'),
						type:'get',
						dataType:'html',
						context:$(this),
						beforeSend: function (xhr) {
							xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
						},
						success:function(html){
							$(this).parents('.attend_user_list').replaceWith(html);
						}
					});
					return false;
				}
			});
		});
	};
})(jQuery);